package com.aegean.MonitorExamSYS.monitor.action;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.aegean.MonitorExamSYS.monitor.business.MonitorBusiness;
import com.aegean.MonitorExamSYS.monitor.component.ExamPosition;
import com.aegean.MonitorExaxSYS.model.MonitorQualification;
import com.aegean.MonitorExaxSYS.model.MonitorValue;
import com.opensymphony.xwork2.ActionSupport;

@Controller("NavigationMonitorArrange")
@Scope("prototype")
public class NavigationMonitorArrange extends ActionSupport implements
		ServletRequestAware {
	@Resource
	MonitorBusiness business;
	private List<ExamPosition> mqs;
	private int start;
	private int limit;
	private HttpServletRequest request;
	private HttpSession session;
	private int pageNow;// 当前页
	private int totalRows;// 总条例个数
	private int pageCount;// 页数
	public int getPageNow() {
		return pageNow;
	}

	public void setPageNow(int pageNow) {
		this.pageNow = pageNow;
	}

	public int getTotalRows() {
		return totalRows;
	}

	public void setTotalRows(int totalRows) {
		this.totalRows = totalRows;
	}

	public int getPageCount() {
		return pageCount;
	}

	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}

	public List<ExamPosition> getMqs() {
		return mqs;
	}

	public void setMqs(List<ExamPosition> mqs) {
		this.mqs = mqs;
	}

	public int getStart() {
		return start;
	}

	public void setStart(int start) {
		this.start = start;
	}

	private MonitorValue monitor;

	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		limit = 15;
		monitor = (MonitorValue) session.getAttribute("MonitorLogin");
		totalRows = business.showMonitorExamsCount(monitor.getUser_Id());
		if ((totalRows % limit) == 0) {
			pageCount = totalRows / limit;
		} else {
			pageCount = totalRows / limit + 1;
		}
		if (pageNow > pageCount) {
			pageNow = pageCount;
		} else if (pageNow < 1) {
			pageNow = 1;
		}
		start = (pageNow - 1) * limit;
		mqs = business.showMonitorExams(monitor.getUser_Id(), limit, start);
		return SUCCESS;
	}
   public String show()throws Exception{
	    limit = 15;
		monitor = (MonitorValue) session.getAttribute("MonitorLogin");
		totalRows = business.showMonitorExamsCount(monitor.getUser_Id());
		if ((totalRows % limit) == 0) {
			pageCount = totalRows / limit;
		} else {
			pageCount = totalRows / limit + 1;
		}
		if (pageNow > pageCount) {
			pageNow = pageCount;
		} else if (pageNow < 1) {
			pageNow = 1;
		}
		start = (pageNow - 1) * limit;
		mqs = business.showMonitorExams(monitor.getUser_Id(), limit, start);
	    return SUCCESS;
   }
	@Override
	public void setServletRequest(HttpServletRequest arg0) {
		// TODO Auto-generated method stub
		this.request = arg0;
		this.session = request.getSession();
	}

}
